package com.sdleyou.treepro.business.api.prop;

import com.sdleyou.treepro.common.model.utils.ResultVOUtil;
import com.sdleyou.treepro.common.model.vo.ResultVO;
import com.sdleyou.treepro.common.service.UserPropManager;
import com.sdleyou.treepro.system.version.ApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class PropController {

    @Autowired
    private UserPropManager userPropManager;

    /**
     * 获取道具列表
     */
    @ApiVersion(1)
    @PostMapping("/{version}/prop/list")
    public ResultVO userInfo(@RequestParam("user_id") String userId){
        return ResultVOUtil.success(userPropManager.getUserPropList(userId));
    }

    /**
     * 使用道具
     */
    @ApiVersion(1)
    @PostMapping("/{version}/prop/use")
    public ResultVO userInfo(@RequestParam("user_id") String userId,
                             @RequestParam("type") String type,
                             String toUser,
                             @RequestParam(name="multiple", defaultValue = "1") Integer multiple){
        return ResultVOUtil.success(userPropManager.useProp(userId, type, toUser, multiple));
    }

    /**
     * 更新道具信息
     */
    @ApiVersion(1)
    @PostMapping("/{version}/prop/update")
    public ResultVO update(@RequestParam("user_id") String userId){
        userPropManager.update(userId);
        return ResultVOUtil.success();
    }
}
